home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / misc / avmnfaxsrc1_33.lha / timer.c < prev    next >
C/C++ Source or Header  |  1994-05-25  |  2KB  |  84 lines

  1. /* $Header: pd:zvmrcs/timer.c,v 1.1 1993/04/07 18:47:36 rvillari Exp $ */
  2. /* Timer i/o routines */
  3.  
  4. #include <clib/exec_protos.h>
  5. #include <clib/alib_protos.h>
  6. #include <exec/types.h>
  7. #include <exec/ports.h>
  8. #include <exec/tasks.h>
  9.  
  10. #include "timer_proto.h"
  11.  
  12. /* EXPORTS */
  13. struct timerequest* tr = 0;
  14. struct timerequest* tr2 = 0;
  15.  
  16. /* some timer routines that we need */
  17.  
  18. struct timerequest *PrepareTimer() {
  19.   /* return a pointer to a time request.  If any problem, return NULL */
  20.  
  21.   int error;
  22.   
  23.   struct MsgPort *timerport;
  24.   struct timerequest *timerReq;
  25.     
  26.   timerport = CreatePort(0,0);
  27.   if (timerport == 0) 
  28.     goto bad;
  29.   
  30.   timerReq = (struct timerequest *)CreateExtIO(timerport,sizeof(struct timerequest));
  31.   if (timerReq == 0)
  32.     goto bad;
  33.   
  34.   error = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest*)timerReq, 0);
  35.   if (error != 0)
  36.     goto bad;
  37.  
  38.   return(timerReq);
  39.  
  40.  bad:
  41.   if (timerReq) {
  42.     timerport = timerReq->tr_node.io_Message.mn_ReplyPort;
  43.     if (timerport) DeletePort(timerport);
  44.     DeleteExtIO((struct IORequest*)timerReq);
  45.   }
  46.   return 0;
  47. }
  48.  
  49.  
  50. void StartTimer(struct timerequest* timeRequest, ULONG seconds, ULONG microseconds) {
  51.   timeRequest->tr_node.io_Command = TR_ADDREQUEST;   /* add a new timer request */
  52.   timeRequest->tr_time.tv_secs =  seconds;            /* seconds */
  53.   timeRequest->tr_time.tv_micro = microseconds;     /* microseconds */
  54.   SendIO((struct IORequest*) timeRequest );            /* post request to the timer */
  55. }
  56.  
  57. ULONG TimerSignal(struct timerequest* timeRequest) {
  58.   ULONG thisSignal = (1L << timeRequest->tr_node.io_Message.mn_ReplyPort->mp_SigBit);
  59.   return thisSignal;
  60. }
  61.  
  62. void EndTimer(struct timerequest* timeRequest) {
  63.   ULONG timerSignal =  TimerSignal(timeRequest);
  64.  
  65.   AbortIO((struct IORequest*)timeRequest);
  66.  
  67.   WaitIO((struct IORequest*)timeRequest);
  68.  
  69.   SetSignal(0L, timerSignal);
  70. }
  71.  
  72. void DeleteTimer(struct timerequest* timeRequest) {
  73.   struct MsgPort *tp;
  74.  
  75.   CloseDevice((struct IORequest*)timeRequest);
  76.   tp = timeRequest->tr_node.io_Message.mn_ReplyPort;
  77.   DeletePort(tp);
  78.   DeleteExtIO((struct IORequest*)timeRequest);
  79. }
  80.  
  81.  
  82.  
  83.  
  84.